package org.ala.tiktools.sharddb.mybatis.summary.impls;

import org.ala.tiktools.mybatis.interfaces.IOrderBy;
import org.ala.tiktools.sharddb.mybatis.router.ShardInfo;
import org.ala.tiktools.sharddb.mybatis.summary.IShardListOrderBySummary;
import org.ala.tiktools.sharddb.mybatis.summary.IShardListSummary;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 列表类型的结果集合并
 * @author ala
 * @date 2025-02-21 12:32
 */
public class ShardListSummary<E> implements IShardListSummary<E>, IShardListOrderBySummary<E> {


    @Override
    public List<E> summary(IOrderBy<E> orderBy, Map<ShardInfo, List<E>> result) {
        List<E> res = summary(result);
        res.sort(orderBy);
        return res;
    }

    @Override
    public List<E> summary(Map<ShardInfo, List<E>> result) {
        List<E> res = new ArrayList<>();
        result.values().forEach(res::addAll);
        return res;
    }
}
